<template>
  <div>
    <router-view></router-view>
    <div v-if="this.$route.name === '开发者审核'">
      <div class="el">
        <!-- <el-button type="primary" @click="addUser">添加举报信息</el-button> -->
        <el-button type="text" @click="dealedMsg()"
          >查看不通过开发者信息</el-button
        >
        <!-- <el-button type="text" @click="dealMsg()">查看未处理举报信息</el-button> -->
      </div>
      <!-- 表格 -->
      <el-table :data="list" border style="width: 100%">
        <el-table-column
          prop="father_idnumber"
          label="开发者身份证号"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="father_login_date"
          label="开发者注册日期"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="father_name"
          label="开发者公司名称"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="father_power"
          label="开发者权限"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.father_power === '0' ? '正常' : '封号' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="father_real_name"
          label="开发者真实姓名"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="father_state"
          label="开发者状态"
          header-align="center"
          align="center"
        >
          <!-- 插槽三元表达式 -->
          <template slot-scope="scope">
            <span>{{
              scope.row.father_state === 0 ? '待审核' : '审核不通过'
            }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="user_name" label="用户姓名" header-align="center" align="center">
        </el-table-column>
        <el-table-column
          prop="administrators_name"
          label="管理员名称"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="father_audit_date"
          label="审核日期"
          header-align="center"
          align="center"
        >
        </el-table-column>
        <el-table-column label="操作" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button
              type="warning"
              plain
              @click="changeStatus(scope.$index, scope.row)"
              size="mini"
              >更改状态</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        class="dialog"
        title="修改信息"
        :visible.sync="dialogVisible"
        :show-close="false"
        :before-close="changeStatus"
      >
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item prop="radio" label="状态">
            <el-radio-group v-model="ruleForm.radio">
              <el-radio :label="0">待审核</el-radio>
              <el-radio :label="1">通过</el-radio>
              <el-radio :label="2">审核不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注" prop="remarks">
            <el-input v-model="ruleForm.remarks"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="escButton()">取消</el-button>
          <el-button @click="changeUser()" type="primary">修改</el-button>
        </div>
      </el-dialog>
      <!-- 分页 -->
      <el-pagination
        @current-change="changePage"
        v-show="shows"
        :current-page.sync="currentPage"
        :page-size="pageSize"
        background
        layout="prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import http from '../api/index';
export default {
  data() {
    return {
      list: [],
      currentPage: 1,
      pageSize: 1,
      shows: true,
      total: 0,
      dialogVisible: false,
      father_power: '',
      app_father_id: '',
      time: '',
      ruleForm: {
        radio: '',
        remarks: '',
      },
      rules: {
        radio: [{ required: true, message: '请选择状态', trigger: 'blur' }],
      },
    };
  },
  mounted() {
    http
      .getCheckedDevlop({
        pages: 1,
        father_state: 0,
      })
      .then((r) => {
        console.log(r);
        this.list = r.data;
        this.total=parseInt(r.msg);
      });
  },
  methods: {
      // 分页
    changePage(val) {
      http
        .getCheckedDevlop({
          pages: val,
          father_state: 0,
        })
        .then((r) => {
          console.log(r);
          this.list = r.data;
          this.total = parseInt(r.msg);
        });
    },
    //  不通过信息
    dealedMsg() {
      this.$router.push('/index/check/checkDevlop/checkDevErr');
    },
    //更改状态
    changeStatus(index, row) {
      this.dialogVisible = true;
      console.log(row);
      this.ruleForm.radio = row.father_state;
      this.father_power = row.father_power;
      this.app_father_id = row.app_father_id;
      console.log(this.ruleForm.radio);
      console.log(this.father_power);
      console.log(this.app_father_id);
    },
    // 修改成功
    changeUser() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          let date = new Date();
          let year = date.getFullYear();
          let month = date.getMonth() + 1;
          let day = date.getDate();
          this.time =
            year +
            '.' +
            (month < 10 ? '0' + month : month) +
            '.' +
            (day < 10 ? '0' + day : day);
          http
            .changeCheckedDevloper({
              father_state: this.ruleForm.radio,
              father_power: this.father_power,
              app_father_id: this.app_father_id,
              administrators_id: 1001,
              father_audit_text: this.ruleForm.remarks,
              father_audit_date: this.time,
            })
            .then((r) => {
              console.log(r);
              http
                .getCheckedDevlop({
                  pages: this.currentPage,
                  father_state: 0,
                })
                .then((r) => {
                  console.log(r);
                  this.list = r.data;
                  this.total=parseInt(r.msg);
                });
            });
          console.log(this.time);
          console.log(this.ruleForm.radio);
          console.log(this.father_power);
          console.log(this.app_father_id);
          console.log(this.ruleForm.remarks);
          this.dialogVisible = false;
        }
      });
    },
    // 取消修改
    escButton() {
      this.$refs.ruleForm.resetFields();
      this.dialogVisible = false;
      // this.dialogFormVisible = false;
    },
  },
};
</script>